package com.desire.factory;

import com.desire.bean.User;
import com.desire.remote.UserRemoteClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description:
 * @Author: littleDesire
 * @Date: 2022-06-10 19:27
 * @Version: 1.0
 */
@Component
public class UserRemoteClientFallbackFactory implements FallbackFactory<UserRemoteClient> {
    private final Logger logger = LoggerFactory.getLogger(UserRemoteClientFallbackFactory.class);

    /**
     * 回退机制 实现FallbackFactory接口
     * @param cause cause of an exception. May be null.
     * @return
     */
    @Override
    public UserRemoteClient create(Throwable cause) {
        logger.error("UserRemoteClient回退:", cause);
        return new UserRemoteClient() {
            @Override
            public Map<String, Object> queryUser() {
                Map<String, Object> map = new HashMap<>();
                map.put("code", 0);
                map.put("msg", "工厂降级处理");
                return map;
            }

            @Override
            public Map<String, Object> queryPath(String id) {
                return null;
            }

            @Override
            public Map<String, Object> queryParams(String username, String password) {
                return null;
            }

            @Override
            public void queryGetMap(Map<String, Object> map) {

            }

            @Override
            public void queryPostMap(Map<String, Object> map) {

            }

            @Override
            public void queryPostUser(User user) {

            }

            @Override
            public void queryStringQueryMap(Map<String, Object> map) {

            }

            @Override
            public void queryStringQueryMapUser(User user) {

            }
        };
    }
}
